package com.groot.medical.service;

import java.util.List;

import com.groot.medical.dao.AdministrativeAreaDao;
import com.groot.medical.dao.AdministrativeAreaDaoImpl;
import com.groot.medical.entity.AdministrativeArea;
import com.groot.medical.entity.PageBean;

public class AdministrativeAreaServiceImpl implements AdministrativeAreaService {
	private AdministrativeAreaDao areaDao = new AdministrativeAreaDaoImpl();
	@Override
	public PageBean findByPage(int pageNum, int pageSize) {
		int totalRecord = areaDao.getAllAreaCount();
		PageBean pageBean = new PageBean<>(pageNum, pageSize, totalRecord);
		int startIndex = pageBean.getStartIndex();
		pageBean.setList(areaDao.findAreaByPage(startIndex,pageSize));
		return pageBean;
	}
	@Override
	public List<AdministrativeArea> findAllAreaInfo() {
		List<AdministrativeArea> areaList = areaDao.findAllAreaInfo();
		return areaList;
	}
	@Override
	public int addAreaInfo(AdministrativeArea area) {
		AdministrativeArea parea=areaDao.findLevelByPid(area.getPid());
		System.out.println(parea);
		String areacode=areaDao.autoCreateAreaCode(area,parea);
		System.out.println("maxcode:"+areacode);
		area.setAreaCode(areacode);
		area.setAreaLevel(parea.getAreaLevel());
		return areaDao.addAreaInfo(area);
	}
	@Override
	public List findOtherAreaInfo() {
		List<AdministrativeArea> areaList = areaDao.findOtherAreaInfo();
		return areaList;
		
	}
	@Override
	public List findContryAreaInfo() {
		List<AdministrativeArea> areaList = areaDao.findContryAreaInfo();
		return areaList;
	}
	@Override
	public List findTownAreaInfo(String areacode) {
		List<AdministrativeArea> areaList = areaDao.findTownAreaInfo(areacode);
		return areaList;
	}
	@Override
	public List findVillageAreaInfo(String areacode) {
		List<AdministrativeArea> areaList = areaDao.findVillageAreaInfo(areacode);
		return areaList;
		
	}
	@Override
	public List findGroupAreaInfo(String areacode) {
		List<AdministrativeArea> areaList = areaDao.findGroupAreaInfo(areacode);
		return areaList;
		
	}
	@Override
	public List findAllTownInfo() {
		List<AdministrativeArea> towns = areaDao.findAllTownInfo();
		return towns;
	}
	@Override
	public List<AdministrativeArea> findContryAndTown() {
		List<AdministrativeArea> area = areaDao.findContryAndTown();
		return area;
		
	}
	@Override
	public AdministrativeArea findAreaInfoById(String id) {
		AdministrativeArea area = areaDao.findAreaInfoById(id);
		return area;
	}
	@Override
	public void editArea(AdministrativeArea area) {
		areaDao.editArea(area);
		
	}

}
